package com.baizhi.cmfz.service.impl;

import com.baizhi.cmfz.dao.ArticleDao;
import com.baizhi.cmfz.entity.Article;
import com.baizhi.cmfz.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
public class ArticleServiceImpl implements ArticleService {

    @Autowired
    private ArticleDao articleDao;
    @Override
    public Map showPageArticle(int page, int limit) {
        int offset=(page-1)*limit;
        List<Article> list=articleDao.showPageArticle(offset,limit);
        int count=articleDao.showCount();
        Map map=new HashMap();
        if(count>0){
            map.put("data",list);
            map.put("count",count);
            map.put("code",0);
            map.put("msg","");
        }

        return  map;
    }

    @Override
    public Map insertArticle(Article article) {
        int count=articleDao.insertArticle(article);
        Map map=new HashMap();
        if(count>0){
            map.put("isInsert","添加成功");
        }else {
            map.put("isInsert","添加失败");
        }
        return  map;
    }

    @Override
    public Map deleteArticle(int id) {
       int count=articleDao.deleteArticle(id);
       Map map=new HashMap();
       if(count>0){
           map.put("isDelete","删除成功");
       }else {
           map.put("isDelete","删除失败");
       }
       return map;
    }

    @Override
    public Article showOne(int id) {
        return articleDao.showOne(id);
    }

    @Override
    public Map updateArticle(Article article) {
        int count =articleDao.updateArticle(article);
        Map map=new HashMap();
        if(count>0){
            map.put("isUpdate","修改成功");
        }else {
            map.put("isUpdate","修改失败");
        }
        return map;
    }

    @Override
    public List<Article> showSix(int count) {
        return articleDao.showSix(count);
    }
}
